define(function(){
	function particulars(){
		var cookieStr = $.cookie("MCLuserCookie");
		if(cookieStr){
			$("#top .ul1").css("display","none");
			$("#top .ul2").css("display","block");
		}else{
			$("#top .ul1").css("display","block");
			$("#top .ul2").css("display","none");
		}
		//退出按钮
		$(".quit").click(function(){
			$("#top .ul1").css("display","block");
			$("#top .ul2").css("display","none");
			$(this).attr("href","index.html");
		})
		$('.second').on({
			"mouseover" : function(){
				$('.tel').animate({
						"left" : "-230px",
						"opacity" : '100'
					},500)
				},
			"mouseout" : function(){
				$('.tel').animate({
						"left" : "-300px",
						"opacity" : 0
					},500)
				}
			})
		//滚动事件
		$(window).scroll(function(){
			var $top = $(window).scrollTop();
			if($top >= 200){
					$('.returnTop').fadeIn(1000,'linear');
			}else{
				$('.returnTop').fadeOut(1000,'linear');
			}
			$('.returnTop').click(function(){
				$top = 0;
			})
		})
		$('.description').each(function(index,value){
			$(this).on({
				"mouseover" : function(){
					$(this).css("color","#5d5759");
				},
				"mouseout" : function(){
					$(this).css("color","#888");
				}
			})
		})
		//获取说明大图
		$.getJSON("particulars.json",function(json){
			$.each(json.explainImg,function(index,value){
				var img = $("<img/>");
				img.attr("src",value);
				img.prependTo($(".imags"));
				zoomBig()
			});
		})
		//文字颜色更换
		$(".brand").on({
			"mouseover" : function(){
				$(this).css("color","#666");
			},
			"mouseout" : function(){
				$(this).css("color","#888");
			}
		})
		//数量改变
		var $num1 = parseInt($('.product_number').html());
		$('.addnum').click(function(){
			$num1 ++;
			$('.product_number').html(($num1));
		})
		$('.substractnum').click(function(){
			$num1 --;
			if($num1 <= 1){
				$num1 = 1;
				$('.product_number').html($num1);
			}else{
				$('.product_number').html($num1);
			}
		})
		//分享到事件
		$('.shareTo').on({
			"mouseover" : function(){
				$('.shareToAnwhere').css("display","block");
				$('.shareToAnwhere').on({
					"mouseenter" : function(){
						$('.shareToAnwhere>a').each(function(index,value){
							$(this).on({
							"mouseover" : function(){
									$(this).css("backgroundColor","#f3f3f3");
								},
							"mouseout" : function(){
									$(this).css("backgroundColor","white");
								}
							})
						})
						$(".more").on({
							"mouseenter" : function(){
								$(this).css("color",'blue');
							},
							"mouseleave" : function(){
								$(this).css("color",'#999');
							}
						})
					},
					"mouseleave" : function(){
						$(this).css("display","none");
					}
				})
			}
		})
		//图片更换事件
		$(".smallImg a img").each(function(index,value){
			$(this).click(function(){
				$(".images p img").attr("src",value.src);
			})
		})
		//ul的鼠标滑动事件
		$('.explain-con .left ul li').each(function(index,value){
			$(value).mouseover(function(){
				if(index != 0){
					$('.explain-con .left ul li').eq(index).css("background","#B2B2B2");
					$('.explain-con .left ul li').eq(index).children("a").css("color","white");
					$(".explain-con .left ul li").eq(0).css("background","#E1E1E1");
					$(".explain-con .left ul li").eq(0).children("a").css("color","#888888");
				}
				if(index == 1){
					$('.imags').css('display',"none");
					$(".commodity").css("display","none");
					$(".comment").css("display","block");
				}else if(index == 2){
					$(".imags").css("display","none");
					$(".comment").css("display","none");
					$(".commodity").css("display","block");
				}else if(index == 0){
					$('.imags').css('display',"block");
					$(".commodity").css("display","none");
					$(".comment").css("display","none");
					$('.explain-con .left ul li').eq(index).css("background","#B2B2B2");
					$('.explain-con .left ul li').eq(index).children("a").css("color","white");
				}
			})
			$(value).mouseout(function(){
				if(index == 1 || index == 2){
					$(".explain-con .left ul li").eq(index).css("background","#E1E1E1");
					$(".explain-con .left ul li").eq(index).children("a").css("color","#888888");
				}
			})
		})
		//商品问答
			$.getJSON("particulars.json",function(json){
				$(json.customer).each(function(index,value1){
					$('.customers').eq(index).html(value1 + "&nbsp;:");
				})
				$(json.question).each(function(index,value2){
					$('.question').eq(index).html(value2);
				})
				$(json.answer).each(function(index,value){
					$('.answer').eq(index).html(value);
				})
			})
		//相关产品
		$.getJSON("particulars.json",function(json){
			$(json.product_oneImg).each(function(index,value){
				var $img = $("<img/>");
				$img.attr("src",value);
				$('.img_box span').eq(index).append($img);
			})
			$(json.product_oneName).each(function(index,value){
				$("._one_name").eq(index).html(value);
			})
			$(json.product_onePrice).each(function(index,value){
				$('.price_one').eq(index).html("￥" + value);
			})
		})
		$("._one_name").on({
			"mouseover" : function(){
				$(this).css("color","#666");
			},
			"mouseout" : function(){
				$(this).css("color",'#888');
			}
		})
		//添加到购物车
		$('.addcart').click(function(){
			$('#tilt').css("display",'block');
			$('.ready').animate({"top" : "280px"},10);
			//获取id
			var id = $(".part_right").attr("data_id");
			//获取图片
			var $img = $(".images p img").attr("src");
			//获取名称
			var $name = $('.part_right>p').eq(0).html();
			//获取商品编号
			var $number = $('.part_right p:eq(1) span').eq(1).html().substring(10);
			//获取数量
			var $num = $('.product_number').html();
			//获得单价
			var $price = $(".price").html().substring(1);
			var cookieStr = $.cookie("article") ? $.cookie("article") : "";
			var cookieObj = convertcookieStrToCookieObj(cookieStr);
			 if(id in cookieObj){
			 	cookieObj[id].num += Number($num);
			 }else{
			 	console.log($num);
			 	cookieObj[id] = {
			 		"src" : $img,
			 		"name" : $name,
			 		"numbers" : $number,
			 		"num" : $num,
			 		"price" : $price
			 	};
			}
//			console.log(cookieObj)
			cookieStr = convertObjToCarStr(cookieObj);
//			console.log(cookieStr);
			$.cookie("article",cookieStr,{expires : 7,path : "/"});
			console.log($.cookie("article"));
		})
		//关闭事件
		$('.closeBtn2').click(function(){
			$('#tilt').css("display",'none');
			$('.ready').animate({"top" : "-300px"},10);
		})
		//放大镜效果
		//获取元素
		//外层最大的盒子
		function zoomBig(){
			var box = document.getElementsByClassName("images")[0];
			//装图片的盒子		
			var imgBox = document.getElementsByClassName("imgBox")[0];
			//滑动的盒子
			var floatBox = document.getElementsByClassName("floatBox")[0];
			//装放大图片的盒子
			var show = document.getElementsByClassName("reveal")[0];
			//获取遮罩层
			var tile = document.getElementsByClassName("screen")[0];
			//获取大图
			var bigImg = document.getElementsByClassName("bigImg")[0];
	/*		console.log(box);
			console.log(imgBox);
			console.log(floatBox);
			console.log(show);
			console.log(tile);
			console.log(bigImg);
	*/		
			tile.onmouseover = function(){
				floatBox.style.display = "block";
				show.style.display = 'block';
			}
			tile.onmouseout = function(){
				floatBox.style.display = "none";
				show.style.display = "none";
			}
			tile.onmousemove = function(evt){
				var e = evt || window.event;
				var left = e.pageX - box.offsetLeft - imgBox.offsetLeft - floatBox.offsetWidth / 2;
				var top = e.pageY - box.offsetTop - imgBox.offsetTop - floatBox.offsetHeight / 2;	
				if(left <= 0){
					left = 0;
				}else if(left > imgBox.offsetWidth - floatBox.offsetWidth){
					left = imgBox.offsetWidth - floatBox.offsetWidth;
				}
				if(top <= 0){
					top = 0;
				}else if(top > imgBox.offsetHeight - floatBox.offsetHeight){
					top = imgBox.offsetHeight - floatBox.offsetHeight;
				}
				floatBox.style.left = left + "px";
				floatBox.style.top = top + 'px';
				//比例
				var pX = left / (tile.offsetWidth - floatBox.offsetWidth);
				var pY = top / (tile.offsetHeight - floatBox.offsetHeight);
				//大图显示
				bigImg.setAttribute("src",bigImg.parentNode.children[0].getAttribute("src"));
				bigImg.style.left = -(pX * (bigImg.offsetWidth - show.offsetWidth)) + 'px';
				bigImg.style.top = -(pY * (bigImg.offsetHeight - show.offsetHeight)) + "px";
			}
		}
		}
		
	function convertcookieStrToCookieObj(cookieStr){
		if(!cookieStr){
			return {};
		}
		var goods = cookieStr.split(":");
		var obj = {};
		for(var i = 0;i < goods.length;i ++){
			var data = goods[i].split(",");
			obj[data[0]] = {
				src : data[1],
				name : data[2],
				numbers : data[3],
				num : parseInt(data[4]),
				price : parseFloat(data[5])
			}
		}
		return obj;
	}
	function convertObjToCarStr(obj){
		var cookieStrs = "";
		for(var id in obj){
			if(cookieStrs){
				cookieStrs += ":";
			}
			cookieStrs += id + "," + obj[id].src + "," + obj[id].name + "," + obj[id].numbers + "," + obj[id].num + "," + obj[id].price;
		}
		return cookieStrs;
	}
	return {
		particulars : particulars
	}
})